#include <stdio.h>
#include <string.h>
#include "squid.h"
#include "colorido.h"

int squid_parse(struct squid_request *entry,char *line){
	char *p;
	int pos=0;
	char *nextval;
	char delim;
	int i=0;

	if(entry == NULL || line==NULL)return FALSE;
	memset(entry,0,sizeof(squid_t));


	p=nextval=line;
	delim = ' ';

	while(*p!='\0')
		if(*p++ == ' ')
			i++;
	p=line;

	if(i!=5){
		return FALSE;
	}

	while(*p!='\0'){
		if(*p == delim || *p == '\r' || *p == '\n'){
			switch(pos++){
				case 0:
					entry->requestid = nextval;
					break;
				case 1:
					entry->url = nextval;
					delim = '/';
					break;
				case 2:
					entry->ip = nextval;
					delim=' ';
					break;
				case 3:
					entry->fqdn = nextval;
					break;
				case 4:
					entry->ident = nextval;
					break;
				case 5:
					entry->method = nextval;
					break;
				case 6:
					entry->group = nextval;
					break;
				default:
					return FALSE;
			}

			if(*p == '\r' || *p == '\n'){
				*p='\0';
				break;
			}else
				*p='\0';

			nextval = ++p;
		}else{
			p++;
		}
	}
	*p='\0';

	return TRUE;

}

